
'use strict';

angular.module('myApp.salary', [])

.controller('salaryCtrl', ['$scope','$http', 
    function($scope,$http) {
    $http.get('v1/salary').success(function(data){
        $scope.salarys = data.message['data'];
         console.log(data.message['data']);
    });

    $http.get('v1/teacher').success(function(data){
        $scope.model = data.result['data'];
         console.log($scope.model);
    });

    $scope.add_othermoney = function(addother){
    	addother.teacher_id = $scope.m.id;
        addother.month = $('#month').val();
        $scope.tem = angular.copy(addother);
        console.log($scope.tem);
        $http.post('v1/salary_others',$scope.tem).success(function(data){
            if( !data.error ){
                alert("新增成功","success");
                $http.get('v1/salary').success(function(data){
                $scope.salarys = data.message['data'];
                 console.log( data);
            });
            }else{
                alert(data.message);
            }
        });
    };

    $scope.del = function(other_salary,other){
        $http.delete('v1/salary_others/'+other.id).success(function(data){
            if( !data.error ){
                other_salary.splice(other_salary.indexOf(other),1);
                alert("删除成功","success");
            }else{
                alert(data.message);
            }
        });
    }
    $('.year').bootstrapMonthpicker();
}]);